Fix TypeError crash in fetch_vulnerabilities when VulnerableCode is unreachable#2108
Closed
harshverma27 wants to merge 2 commits into
Closed
Fix TypeError crash in fetch_vulnerabilities when VulnerableCode is unreachable#2108harshverma27 wants to merge 2 commits into
harshverma27 wants to merge 2 commits into
Conversation
…nreachable bulk_search_by_purl() returns None when request_post() catches a network error or HTTP failure. The loop in fetch_vulnerabilities() iterated over the result directly, crashing with TypeError: 'NoneType' is not iterable. Add a guard that skips the batch and logs a warning when response_data is falsy, so a VulnerableCode outage degrades gracefully instead of aborting the entire pipeline run. Fixes aboutcode-org#2107 Signed-off-by: Harsh Verma <harshkardam246@gmail.com>
Signed-off-by: Harsh Verma <harshkardam246@gmail.com>
ede5c1e to
76c32e9
Compare
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bulk_search_by_purl()returnsNonewhenrequest_post()catches a network error or HTTP failure. The loop infetch_vulnerabilities()iterated over the result directly, crashing withTypeError: 'NoneType' is not iterable.Added a guard that skips the batch and logs a warning when
response_datais falsy, so a VulnerableCode outage degrades gracefully instead of aborting the entire pipeline run.Issues
Changes
scanpipe/pipes/vulnerablecode.pyAdded a
if not response_dataguard inside thefetch_vulnerabilitiesloop. Whenbulk_search_by_purl()returnsNone(network failure, timeout, or HTTP error), the batch is now skipped with a warning logged to the pipeline run log rather than crashing with aTypeError.scanpipe/tests/pipes/test_vulnerablecode.pyAdded
test_scanpipe_pipes_vulnerablecode_fetch_vulnerabilities_none_responsewhich mocksbulk_search_by_purlto returnNoneand asserts that the function completes without error, no vulnerabilities are stored, and the warning message appears in the log output.Checklist
This fix was identified with assistance from Claude (Anthropic). The analysis, implementation, and testing were reviewed and understood by me before submission.